package com.example.selfcontrol.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.example.selfcontrol.config.Response;
import com.example.selfcontrol.dto.ArticleInfoDTO;
import com.example.selfcontrol.dto.TalkRespDTO;
import com.example.selfcontrol.dto.WxArticleInfoDTO;
import com.example.selfcontrol.entity.Article;
import com.example.selfcontrol.entity.ArticleCategory;
import com.example.selfcontrol.service.ArticleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.models.auth.In;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/articles")
@Api(value = "文章视图")
public class ArticleController {
    @Autowired
    private ArticleService articleService ;

    @GetMapping("/")
    @ApiOperation("获取文章 | 传入文章Id 和 用户Id")
    public Response getArticle(int articleId , int userId ) {
        return articleService.getArticle(articleId,userId) ;
    }

    @GetMapping("/category/count/{cid}")
    @ApiOperation("获取分类下的文章总数 | -1 表示全部文章数量")

    public int ArticleCategoryCount(@PathVariable int cid) {
        return articleService.ArticleCategoryCount(cid) ;
    }

    @GetMapping("/category/{cid}")
    @ApiOperation("分页获取分类下文章")
    public List<Article> ArticleCategoryPagination(
            @PathVariable int cid,
            @RequestParam(value = "pageNum") int pageNum,
            @RequestParam(value = "pageSize") int pageSize
            )
    {
        return articleService.ArticleCategoryPagination(cid,pageNum,pageSize) ;
    }

    @GetMapping("/category/info")
    @ApiOperation("获取主页面所有的文章")
    public List<List<Article>> ArticleCategoryInfo() {
        return articleService.ArticleCategoryInfo() ;
    }

//    @GetMapping("/category/users/")
//    @ApiOperation("获取用户的发布文章")
//    public List<Article> UserArticles(@RequestBody int userId) {
//        return articleService.UserArticles(userId);
//    }

    @PostMapping("/auth/create")
    @ApiOperation("创建文章")
    public Response createArticle(@RequestBody Article article) {
        return  articleService.createArticle(article) ;
    }

    @PutMapping("/auth/{id}")
    @ApiOperation("修改id文章")
    public Response modifyArticle(@RequestBody Article article) {
        return articleService.modifyArticle(article) ;
    }

    @DeleteMapping("/auth/{id}")
    @ApiOperation("删除id文章")
    public Response deleteArticle(@PathVariable Integer id) {
        return articleService.deleteArticle(id) ;
    }


    @GetMapping("/personal/count")
    @ApiOperation("userId用户的文章数量")
    public int CountPersonalArticles(Long userId) {
        return articleService.CountPersonalArticles(userId) ;
    }

    @GetMapping("/personal/articleInfo")
    @ApiOperation("侧边栏 | 我的文章，分页获取")
    public List<ArticleInfoDTO> PersonalArticlesInfo(int userId, int pageNum, int pageSize) {
        return articleService.PersonalArticlesInfo(userId,pageNum,pageSize) ;
    }

    @GetMapping("/all")
    @ApiOperation("全部文章的分页  | 没有返回[]")
    public List<Article> AllarticlesPagination(int pageNum, int pageSize) {
        return articleService.AllarticlesPagination(pageNum,pageSize) ;
    }

    @GetMapping("/article/type")
    @ApiOperation("获取全部的文章分类")
    public List<ArticleCategory> getCategory() {
        return articleService.getCategory() ;
    }

    @GetMapping("/talk/type")
    @ApiOperation("获取全部的文章分类")
    public List<ArticleCategory> getTalkType() {
        return articleService.getTalkType() ;
    }


    @GetMapping("/wx/articleInfo")
    @ApiOperation("微信端文章简介 | cid表示文章分类，传入-1表示全部文章")
    public List<WxArticleInfoDTO> getWxArticleInfo(int cid , int userId , int pageNum, int pageSize,int sortBy) {
        return articleService.getWxArticleInfo(cid,userId,pageNum,pageSize,sortBy) ;
    }

    @GetMapping("/search")
    @ApiOperation("通过关键词查询含有的文章")
    public List<Article> SearchWordContained(String word , int pageNum , int pageSize) {
        return articleService.SearchWordContained(word,pageNum,pageSize) ;
    }

    @PutMapping("/update/data")
    @ApiOperation("更新文章数据")
    public Response UpdateArticle(Long articleId, Long untilId) {
        return articleService.UpdateArticle(articleId,untilId) ;
    }


    @GetMapping("/talk")
    @ApiOperation("获取说说的数据")
    public List<TalkRespDTO> getTalkInfoList(int userId , int pageNum, int pageSize) {
        return articleService.getTalkInfoList(userId,pageNum,pageSize) ;
    }
}
